package com.wanho.java157.controller;

import com.wanho.java157.Car;
import com.wanho.java157.result.R;
import com.wanho.java157.vo.CustomerVo;
import com.wanho.java157.vo.GoodsVo;
import com.wanho.java158.CarService;
import com.wanho.java158.GoodsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api/core/goods")
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    @GetMapping("/index")
    public R listAll(){
        List<GoodsVo> goodsVos = goodsService.selectAll();
        return R.ok().data("list", goodsVos).message("获取列表成功");
    }

    @DeleteMapping("/remove/{goodsId}")
    public R removeById(
            @PathVariable Integer goodsId) {
        boolean result = goodsService.delete(goodsId);
        if (result) {
            return R.ok().message("删除成功");
        } else {
            return R.error().message("删除失败");
        }
    }


    @PutMapping("/update")
    public R updateById(
            @RequestBody GoodsVo goodsVo){


        boolean result = goodsService.update(goodsVo) ;
        if(result){
            return R.ok().message("更新成功");
        }else{
            return R.error().message("更新失败");
        }
    }

}
